import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex)

export default new Vuex.Store({
  	state: {
		openid:null,//用户openid
		userState:null,//判断是否为加盟商
		payList: [],  //  生成订单的商品
		payGoods: {}, //  立即购买生成订单的单个商品
		payOrder: {}, //  支付页需要的订单信息
  	},
	mutations: {

		userState(state, userstate) {
			state.userState = userstate
		},
		setOpenId(state, data) {
			state.openid = data
		},
		payGoods(state, data) {
			state.payGoods = data
		},
		payOrder(state, data) {
			state.payOrder = data
		},
		pushList(state, list) {
		  state.payList = list
		}
	},
  	actions: {

		userState({ commit }, userstate) {
			commit('userState', userstate)
		},
		setOpenId({ commit }, data) {
			commit('setOpenId', data)
		},
		payGoods({ commit }, data) {
			commit('payGoods', data)
		},
		payOrder({ commit }, data) {
			commit('payOrder', data)
		},
		pushList({ commit }, list) {
			commit('pushList', list)
		}
  	},
  	modules: {

	},
	plugins: [createPersistedState({
		storage: window.sessionStorage
	})]
})
